#
#--------------------------------------------------------------------------
# php image
#--------------------------------------------------------------------------
#

ARG PHP_VERSION=${PHP_VERSION}
FROM php:${PHP_VERSION}-fpm

LABEL maintainer="sun <727638417@qq.com>"

# 安装必要的 php 依赖包
RUN apt-get update && \ 
	apt-get install -qq git vim curl wget libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev libbz2-dev libnss3

# 安装composer
RUN curl --silent --show-error https://install.phpcomposer.com/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 安装 php 扩展
RUN apt-get install libzip-dev zip unzip -y && \
    docker-php-ext-configure zip --with-libzip && \
    docker-php-ext-install pdo pdo_mysql zip gd sockets pcntl opcache bcmath tokenizer mbstring

# RUN pecl channel-update pecl.php.net && pecl install memcached mcrypt-1.0.1 mongodb && docker-php-ext-enable memcached mongodb

# 安装 gd iconv 扩展
RUN apt-get update && apt-get install -y \
      libfreetype6-dev \
      libjpeg62-turbo-dev \
      libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

# 安装 redis 扩展
RUN pecl install redis \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable redis

# 安装swoole
# RUN pecl install swoole

# RUN docker-php-ext-enable swoole

# 安装Node
RUN apt-get update &&\
    apt-get install -y --no-install-recommends gnupg &&\
    curl -sL https://deb.nodesource.com/setup_10.x | bash - &&\
    apt-get update &&\
    apt-get install -y --no-install-recommends nodejs &&\
    npm config set registry https://registry.npm.taobao.org --global &&\
    npm install --global gulp-cli &&\
    npm install --global cnpm

# 清除安装包
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
    rm /var/log/lastlog /var/log/faillog

# 添加php配置文件
COPY conf/laravel.ini /usr/local/etc/php/conf.d

CMD ["php-fpm"]
